package com.tmsb.bigscreen.config;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/6/30 18:20
 */
@Configuration
public class DataSourceConfig {

  @Bean(name = "mysqlDataSource")
  @ConfigurationProperties(prefix = "spring.datasource.mysql")
  public DataSource MysqlMallDataSource() {
    return DataSourceBuilder.create().build();
  }

//  @Bean(name = "impala")
//  @ConfigurationProperties(prefix = "spring.datasource.impala")
//  public DataSource ImpalaDataSource() {
//    return DataSourceBuilder.create().build();
//  }

  @Bean(name = "impalaDataSource")
  @ConfigurationProperties(prefix = "spring.datasource.impala")
  public DataSource primaryDataSource() {
    return DataSourceBuilder.create().type(HikariDataSource.class).build();
  }
  @Bean(name = "jdbcTemplateImpala")
  public JdbcTemplate jdbcTemplateImpala(@Qualifier("impalaDataSource") DataSource dataSource) {
    return new JdbcTemplate(dataSource);
  }

}

